//
//  UnusedClassesDetector.m
//  LinkMap
//
//  Created by aron on 2022/5/7.
//  Copyright © 2022 ND. All rights reserved.
//

#import "UnusedClassesDetector.h"
#import "BBCMD.h"

@implementation UnusedClassesDetector

- (void)unusedClasses:(NSString *)appPath completion:(void(^)(NSArray *result))completion {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *resultPath = @"/tmp/result.json";
        getUnusedClasses(appPath, resultPath, ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                NSData *jsonData = [NSData dataWithContentsOfFile:resultPath];
                @try {
                    NSArray *result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
                    !completion ?: completion(result);
                } @catch (NSException *exception) {
                    !completion ?: completion(nil);
                }
            });
        });
    });
}

@end
